import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
import java.sql.Driver;

import static java.lang.invoke.MethodHandles.lookup;

public class 调用父类的父类的方法 {
    public static class GrandFather{
       public   void thinking(){
            System.out.println("i am grandfather");
        }
    }
    public static class Father extends GrandFather{
       public   void thinking(){
            System.out.println("i am father");
        }
    }
    public  static class Son extends Father{
       public void thinking(){

            try{
                MethodType mt=MethodType.methodType(void.class);
                // Field impl_lookup = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP");
                // impl_lookup.setAccessible(true);
                // MethodHandles.Lookup  lookup= (MethodHandles.Lookup) impl_lookup.get(null);
                MethodHandle mh=lookup().findSpecial(GrandFather.class,"thinking",mt,Son.class);
                mh.invoke(this);
            }catch(Throwable e){
                e.printStackTrace();
            }
        }
    }
    public static void main(String[] args)throws Exception{

        new Son().thinking();
    }

}
